1. /* slmlsmns.cpp by K.Tsuru */
  2. // function ID = 234
  3. /********************************************************************
  4. SLong class
  5. It subtracts a positive short implemented for the decrement operator.
  6. The statement
  7. return (*this = *this - a);
  8. has a large overhead, because it calls a constructor SLong(a).
  9. *********************************************************************/
  10. #ifndef SN_H
  11. #include "sn.h"
  12. #endif
  13. void SLong::LsMinus(fType a){
  14. if(!a) return;
  15. if(Sign(234) < 0){ // -x - a = -(x+a)
  16. SetSign(1); LsAdd(a); SetSign(-1);
  17. return;
  18. }
  19. if(aHead == 0){ //one figure including a=0
  20. long r = (long)figure[0]-(long)a;
  21. SetLong(r); return;
  22. }
  23. // aHead >0, aTail >= 0, sign > 0
  24. fType rdx = Radix();
  25. int r = (int)rdx-(int)a;
  26. if(figure[0] >= a){
  27. figure[0] -= a;
  28. while(figure[aTail] == 0) aTail++;
  29. } else if(r > 0){ //figure[0] < a < radix
  30. //*this does not become negative because aHead > 0.
  31. fType rdx1 = rdx - 1;
  32. figure[aTail]--; //It borrows one from upper.
  33. if(figure[aHead] == 0) aHead--; // figure[aHead] == 1 && aHead == aTail
  34. for(uint i = 1u; i < aTail; i++) figure[i] = rdx1;
  35. figure[0] = (fType)r; aTail = 0; // r > 0
  36. if( 2u*(aHead+1) <= figure.size() ) DoCutDown();
  37. } else { //a >= radix
  38. *this -= (double)a;
  39. }
  40. }

slmlsmns.cpp : last modifiled at 2017/03/13 14:32:01(1,303 bytes)
created at 2017/10/07 10:26:49
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).